package com.example.treeHole.scheduled;


import com.example.treeHole.dao.ArticleMainMapper;
import com.example.treeHole.dao.NotificationMainMapper;
import com.example.treeHole.utils.Uuid;
import com.example.treeHole.vo.ArticleMain;
import com.example.treeHole.vo.NotificationMain;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Component
public class DelNotification {

    @Autowired
    private ArticleMainMapper articleMainMapper;

    @Autowired
    private NotificationMainMapper notificationMainMapper;

    /**
     * 查询发布文章未审核的
     * 每三十分钟执行一次
     */
    @Scheduled(cron = "0 0/30 * * * ?")
    public void delArticleMain(){
        NotificationMain notificationMain =null;
        List<NotificationMain> notificationMainList = new ArrayList<>();
        List<ArticleMain> articleMainList=articleMainMapper.findNoti();
        if(articleMainList != null && articleMainList.size()>0) {
            for (ArticleMain articleMain : articleMainList) {
                notificationMain.setArticleId(articleMain.getArticleId());
                notificationMain.setNotificationStatus("0");
                notificationMain.setArticleId("1");
                notificationMain.setSendId(articleMain.getCreateBy());
                notificationMain.setCreateDate(new Date());
                notificationMain.setId(Uuid.getUuID());
                notificationMainList.add(notificationMain);
            }
            notificationMainMapper.insertList(notificationMainList);
        }
    }
}
